home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGMISC / FPCHELP.LZH / KERNEL1.HLP < prev    next >
Text File  |  1988-07-27  |  19KB  |  544 lines

  1. \ KERNEL1.HLP
  2.  
  3.         The first 8 bytes in the system are vectors to the Cold and
  4.         Warm start entries.  You can freely jump to them in code
  5.         anytime. The DPUSH and HPUSH labels are space savers.  We
  6.         jump to them in several CODE words when we want to push their
  7.         contents on the Parameter Stack. >NEXT is where all the
  8.         action is.  It is the guts of the Forth Virtual Machine. It
  9.         must advance the interpretive pointer held in the IP
  10.         register pair and jump indirect to what it points to.
  11.  
  12.         We define a few macros here to make our life a little easier
  13.         later.  Using NEXT as a macro allows us to put it inline
  14.         later.
  15.  
  16. RP      Used to hold the depth of the return stack
  17.  
  18. NEST    The runtime code for :  It pushs the current IP onto the
  19.         return stack and sets the IP to point to the parameter field
  20.         of the word being executed.
  21.  
  22. EXIT            ( --- )
  23.         Pop an entry off the return stack and place it into the
  24.         Interpretive Pointer.  Terminates a Hi Level definition.
  25.  
  26. UNNEST          ( --- )
  27.         Same as exit.  Compiled by ; to help decompiling.
  28.  
  29. DODOES
  30.         The runtime portion of defining words.  First it pushes the
  31.         IP onto the return stack and then it pushes the BODY address
  32.         of the word being executed onto the parameter stack.
  33.  
  34. UP              ( --- a1 )
  35.         Holds a pointer to the current USER area. ( multitasking )
  36.  
  37. DOCONSTANT
  38.         The run time code for CONSTANT.  It takes the contents of
  39.         the parameter field and pushes it onto the stack.
  40.  
  41. DOUSER
  42.         The run time code for USER variables.  Places a pointer to
  43.         the current version of this variable on the stack. Needed
  44.         for multitasking.
  45.  
  46. (LIT)
  47.         The runtime code for literals.  Pushes the following
  48.         two bytes onto the parameter stack and moves the IP over
  49.         them.  It is compiled by the word LITERAL.
  50.  
  51. DOBEGIN         ( --- )
  52. DOTHEN          ( --- )
  53.         These words are really just NOOP's. They are used as place holders
  54.         for the Forth decompiler. I know they probably slow things down a
  55.         little bit, but I felt it was important to be able to decompile
  56.         back to source as much as possible.
  57.  
  58. DOAGAIN
  59. DOREPEAT  A special version of BRANCH that is used to mark a return point
  60.         for the decompiler.
  61.  
  62. ?WHILE
  63. ?UNTIL          ( f1 --- )
  64.         A special version of ?BRANCH that is used to mark a return point
  65.         for the decompiler.
  66.  
  67. BRANCH          ( --- )
  68.         Performs an unconditional branch.  Notice that we
  69.         are using absolute addresses insead of relative ones. (fast)
  70.  
  71. ?BRANCH         ( f1 --- )
  72.         Performs a conditional branch.  If the top of the
  73.         parameter stack in True, take the branch.  If not, skip
  74.         over the branch address which is inline.
  75.  
  76. LOOP-EXIT   is a common routine used by (LOOP) and (+LOOP)
  77.         It is called when the loop has terminated and is exited
  78.         normally.
  79.  
  80. UNDO            ( --- )
  81.         Cleans up the return stack so we can EXIT from the current loop
  82.         without crashing, as in DO and "UN"DO.
  83.  
  84. (LOOP)          ( --- )
  85.         the runtime procedure for LOOP.  Branches back to
  86.         the beginning of the loop if there are more iterations to
  87.         do.  Otherwise it exits.  The loop counter is incremented.
  88.  
  89. LOOP-BRANCH
  90.         A common routine needed twice in the 8080
  91.         implementation of (+LOOP).
  92.  
  93. (+LOOP)         ( n1 --- )
  94.         Increment the loop counter by the value on the stack and
  95.         decide whether or not to loop again.  Due to the wierdness
  96.         of the 8080, you have to stand on your head to determine the
  97.         conditions under which you loop or exit.
  98.  
  99. (DO)            ( n1 n2 --- )
  100.         The runtime code compiled by DO. Pushes the inline address
  101.         onto the return stack along with values needed by (LOOP).
  102.  
  103. (?DO)           ( n1 n2 --- )
  104.         The runtime code compiled by ?DO.  The difference between
  105.         ?DO and DO is that ?DO will not perform any iterations if
  106.         the initial index is equal to the final index.
  107.  
  108. BOUNDS          ( a1 n1 --- a2 a3 )
  109.         Given address a1 and length n1, return a2 and a3 the boudry
  110.         addresses for DO ... LOOP.
  111.  
  112. >NEXT           ( --- a1 )
  113.         The address of the inner interpreter.
  114.  
  115. >NEST           ( --- a1 )
  116.         The address of the NEST routine.
  117.  
  118. EXECUTE         ( a1 --- )
  119.         the word whose code field is on the stack.  Very useful for
  120.         passing executable routines to procedures!!!
  121.  
  122. PERFORM         ( a1 --- )
  123.         The word whose code field is stored at the address pointed to by
  124.         a1, the number on the stack.  Same as @ EXECUTE
  125.  
  126. DO-DEFER  The runtime code for deferred words.  Fetches the
  127.         code field and executes it.
  128.  
  129. DOUSER-DEFER   The runtime code for User deferred words.  These
  130.         are identical to regular deferred words except that each
  131.         task has its own version.
  132.  
  133. GO              ( a1 --- )
  134.         Execute code at the given address.
  135.  
  136. NOOP            ( --- )
  137.         One of the most useful words in Forth.  Does nothing.
  138.  
  139. PAUSE           ( --- )
  140.         Used by the Multitasker to switch tasks.
  141.  
  142. I               ( --- n1 )
  143.         returns the current loop index.  It now requires a little more
  144.         calculation to compute it than in FIG Forth but the tradeoff is a
  145.         much faster (LOOP).  The loop index is stored on the Return Stack.
  146.  
  147. J               ( --- n1 )
  148.         returns the loop index of the inner loop in nested DO .. LOOPs.
  149.  
  150. (LEAVE)         ( --- )
  151.         Does an immediate exit of a DO ... LOOP structure.  Unlike
  152.         FIG Forth which waits until the next LOOP is executed.
  153.  
  154. (?LEAVE)        ( f1 --- )
  155.         Leaves if the flag on the stack is true.  Continues if not.
  156.  
  157. LEAVE           ( --- )
  158.         I have to do this to be 83-Standard.
  159.  
  160. @               ( a1 --- n1 )
  161.         Fetch a 16 bit value from addr.
  162.  
  163. !               ( n1 a1 --- )
  164.         Store a 16 bit value at addr.
  165.  
  166. C@              ( a1 --- b1 )
  167.         Fetch an 8 bit value from addr.
  168.  
  169. C!              ( b1 a1 --- )
  170.         Store an 8 bit value at addr.
  171.  
  172. PLACE           ( from count to --- )
  173.         Move the characters at from to to with a preceding length
  174.         byte of len.
  175.  
  176. CMOVE           ( a1 a2 n1 --- )
  177.         Move a set of bytes from the from address to the to address.
  178.         The number of bytes to be moved is count.  The bytes are
  179.         moved from low address to high address, so overlap is
  180.         possible and in fact sometimes desired.
  181.  
  182. CMOVE>          ( a1 a2 n1 --- )
  183.         The same as CMOVE above except that bytes are moved in the
  184.         opposite direction, ie from high addresses to low addresses.
  185.  
  186. SP@             ( --- a1 )
  187.         Return the address of the next entry on the parameter stack
  188.  
  189. SP!             ( a1 --- )
  190.         ( Warning, this is different from FIG Forth )
  191.         Sets the parameter stack pointer to the specified value.
  192.  
  193. RP@             ( --- a1 )
  194.         Return the address of the next entry on the return stack.
  195.  
  196. RP!             ( a1 --- )
  197.         ( Warning, this is different from FIG Forth )
  198.         Sets the return stack pointer to the specified value.
  199.  
  200. DROP            ( n1 --- )
  201.         Throw away the top element of the stack.
  202.  
  203. DUP             ( n1 --- n1 n1 )
  204.         Duplicate the top element of the stack.
  205.  
  206. SWAP            ( n1 n2 --- n2 n1 )
  207.         Exchange the top two elements on the stack.
  208.  
  209. OVER            ( n1 n2 --- n1 n2 n1 )
  210.         Copy the second element to the top.
  211.  
  212. TUCK            ( n1 n2 --- n2 n1 n2 )
  213.         Tuck the first element under the second one.
  214.  
  215. NIP             ( n1 n2 --- n2 )
  216.         Drop the second element from the stack.
  217.  
  218. ROT             ( n1 n2 n3 --- n2 n3 n1 )
  219.         Rotate the top three element, bringing the third to the top.
  220.  
  221. -ROT            ( n1 n2 n3 --- n3 n1 n2 )
  222.         The inverse of ROT.  Rotates the top element to third place.
  223.  
  224. FLIP            ( n1 --- n2 )
  225.         Exhange the hi and low halves of a word.
  226.  
  227. SPLIT           ( n1 --- n2 n3 )
  228.         SPLIT the 16 bit value n1 into two stack entries which are the LOW
  229.         and HIGH bytes of N1. The HIGH byte is on the top of the stack.
  230.  
  231. ?DUP            ( n1 --- n1 n1<>0 | n1=0 )
  232.         Duplicate the top of the stack if it is non-zero.
  233.  
  234. R>              ( --- n1 )
  235.         Pops a value off of the return stack and pushes it onto the
  236.         parameter stack.  It is dangerous to use this randomly!
  237.  
  238. 2R>             ( --- n1 n2 )
  239.         Pops two values off of the return stack and pushes them onto the
  240.         parameter stack.  It is dangerous to use this randomly!  This word
  241.         is equivalent to: R> R> SWAP that is the order of the operator on
  242.         the return stack is maintained when they are placed on the
  243.         parameter stack.
  244.  
  245. R>DROP          ( --- )
  246.         Pops a value off of the return stack and discards it. It is
  247.         dangerous to use this randomly!
  248.  
  249. >R              ( n1 --- )
  250.         Pops a value off of the parameter stack and pushes it onto
  251.         return stack.  It is dangerous to use this randomly!
  252.  
  253. 2>R             ( n1 n2 --- )
  254.         Pops two values off of the parameter stack and pushes them onto the
  255.         return stack.  It is dangerous to use this randomly!  This word
  256.         is equivalent to: "SWAP >R >R" that is the order of the operator on
  257.         the parameter stack is maintained when they are placed on the
  258.         return stack.
  259.  
  260. DUP>R           ( n1 --- n1 )
  261.         Duplicates the value on the parameter stack and pushes it onto
  262.         return stack.  It is dangerous to use this randomly!
  263.  
  264. R@              ( --- n1 )
  265.         Copies the value on the return stack to the parameter stack.
  266.  
  267. 2R@             ( --- n1 n2 )
  268.         Copies the two top values from the return stack to the parameter
  269.         stack. Same as "R> R> 2DUP >R >R SWAP" that is the order of the
  270.         operator on the return stack is maintained when they are placed
  271.         on the parameter stack.
  272.  
  273. PICK            ( n1 --- n2 )
  274.         Reaches into the stack and grabs an element, copying it
  275.         to the top of the stack.  For example, if the stack has 1 2 3
  276.         Then 0 PICK is 3, 1 PICK is 2, and 2 PICK is 1.
  277.  
  278. ROLL            ( n1 --- n2 )
  279.         Similar to SHAKE and RATTLE.  Should be avoided.
  280.         1 ROLL is SWAP, 2 ROLL is ROT, etc.
  281.         ROLL can be useful, but it is slow.
  282.  
  283. AND             ( n1 n2 --- n3 )
  284.         Returns the bitwise AND of n1 and n2 on the stack.
  285.  
  286. OR              ( n1 n2 --- n3 )
  287.         Returns the bitwise OR of n1 and n2 on the stack.
  288.  
  289. XOR             ( n1 n2 --- n3 )
  290.         Returns the bitwise Exclusive Or of n1 and n2 on the stack.
  291.  
  292. NOT             ( n1 --- n2 )
  293.         Does a ones complement of the top.  Equivalent to -1 XOR.
  294.  
  295. TRUE
  296. FALSE           ( --- f1 )
  297.         Constants for clarity.
  298.  
  299. YES     Push a true flag on the stack and jump to next
  300.  
  301. NO      Push a false flag on the stack and jump to next
  302.  
  303. CSET    Set the contents of addr so that the bits that are 1 in n
  304.         are also 1 in addr.  Equivalent to DUP C@ ROT OR SWAP C!
  305.  
  306. CRESET          ( n1 a1 --- )
  307.         Set the contents of addr so the the bits that are 1 in n
  308.         are zero in addr.  Equivalent to DUP C@ ROT NOT AND SWAP C!
  309.  
  310. CTOGGLE         ( a1 n1 --- )
  311.         Flip the bits in addr by the value n.  Equivalent to
  312.         DUP C@ ROT XOR SWAP C!
  313.  
  314. ON              ( a1 --- )
  315.         Set the contents of addr to TRUE
  316.  
  317. OFF             ( a1 --- )
  318.         Set the contents of addr to FALSE
  319.  
  320. +               ( n1 n2 --- n3 )
  321.         Add the top two numbers on the stack and return the result.
  322.  
  323. NEGATE          ( n1 --- n2 )
  324.         Turn the number into its negative.  A twos complement op.
  325.  
  326. -               ( n1 n2 --- n3 )
  327.         Subtracts n2 from n1 leaving the result on the stack.
  328.  
  329. ABS             ( n1 --- n2 )
  330.         Return the absolute value of the 16 bit integer on the stack
  331.  
  332. +!              ( n1 a1 --- )
  333.         Increment the value at addr by n.  This is equivalent to
  334.         the following:   DUP @ ROT + SWAP ! but much faster.
  335.  
  336. C+!             ( b1 a1 --- )
  337.         Increment the byte value at addr by n1. This is equivalent the
  338.         following: "DUP C@ ROT + SWAP C!" but much faster.
  339.  
  340. PC@             ( port# -- n1 )
  341.         Read the 8 bit port# and return value n1.
  342.  
  343. P@              ( port# -- n1 )
  344.         Read the 16 bit port# and return value n1.
  345.  
  346. PC!             ( n1 port# --- )
  347.         Write the byte n1 to the 8 bit port#.
  348.  
  349. P!              ( n1 port# --- )
  350.         Write the value n1 to the 16 bit port#.
  351.  
  352. PDOS            ( a1 drive# --- f1 )
  353.         Read the current DOS path of drive# into the array at a1. The
  354.         string returned will be NULL terminated. F1 returns TRUE if an
  355.         error occured.
  356.  
  357. 2*              ( n1 --- n2 )
  358.         Double the number on the Stack.
  359.  
  360. 2/              ( n1 --- n2 )
  361.         Shift the number on the stack right one bit.  Equivalent to
  362.         division by 2 for positive numbers.
  363.  
  364. U2/             ( n1 --- n2 )
  365.         16 bit logical right shift.
  366.  
  367. U16/            ( n1 --- n2 )
  368.         Four 16 bit logical right shifts. Unsigned divide by 16 decimal.
  369.  
  370. 8*              ( n1 --- n2 )
  371.         Multiply the top of the stack by 8.
  372.  
  373. 1+              ( n1 --- n2 )
  374.         Increment the top of the stack by one.
  375.  
  376. 2+              ( n1 --- n2 )
  377.         Increment the top of the stack by two.
  378.  
  379. 1-              ( n1 --- n2 )
  380.         Decrement the top of the stack by one.
  381.  
  382. 2-              ( n1 --- n2 )
  383.         Decrement the top of the stack by two.
  384.  
  385. U*D     is a synonym for UM*
  386.  
  387. UM/MOD
  388.         This is the division primitive in Forth.  All other division
  389.         operations are derived from it.  It takes a double number,
  390.         d1, and divides by by a single number n1.  It leaves a
  391.         remainder and a quotient on the stack.  For a clearer
  392.         understanding of arithmetic consult Knuth Volume 2 on
  393.         Seminumerical Algorithms.
  394.  
  395. 0=              ( n1 --- f1 )
  396.         Returns True if top is zero, False otherwise.
  397.  
  398. 0<              ( n1 --- f1 )
  399.         Returns true if top is negative, ie sign bit is on.
  400.  
  401. 0>              ( n1 --- f1 )
  402.         Returns true if top is positive.
  403.  
  404. 0<>             ( n1 --- f1 )
  405.         Returns true if the top is non-zero, False otherwise.
  406.  
  407. =               ( n1 n2 --- f1 )
  408.         Returns true if the two elements on the stack are equal,
  409.         False otherwise.
  410.  
  411. <>              ( n1 n2 --- f1 )
  412.         Returns true if the two element are not equal, else false.
  413.  
  414. ?NEGATE         ( n1 n2 --- n3 )
  415.         Negate the second element if the top is negative.
  416.  
  417. U<              ( n1 n2 --- f1 )
  418.         Compare the top two elements on the stack as unsigned
  419.         integers and return true if the second is less than the
  420.         first.  Be sure to use U< whenever comparing addresses, or
  421.         else strange things will happen beyond 32K.
  422.  
  423. U>              ( n1 n2 --- f1 )
  424.         Compare the top two elements on the stack as unsigned
  425.         integers.  True if n1 > n2 unsigned.
  426.  
  427. <               ( n1 n2 --- f1 )
  428.         Compare the top two elements on the stack as signed
  429.         integers and return true if n1 < n2.
  430.  
  431. >               ( n1 n2 --- f1 )
  432.         Compare the top two elements on the stack as signed
  433.         integers and return true if n1 > n2.
  434.  
  435.  
  436. MIN             ( n1 n2 --- n3 )
  437.         Return the minimum of n1 and n2
  438.  
  439. MAX             ( n1 n2 --- n3 )
  440.         Return the maximum of n1 and n2
  441.  
  442. BETWEEN         ( n1 n2 --- f1 )
  443.         Return true if min <= n1 <= max, otherwise false.
  444.  
  445. WITHIN          ( n1 n2 --- f1 )
  446.         Return true if min <= n1 < max, otherwise false.
  447.  
  448. 2@              ( a1 --- d1 )
  449.         Fetch a 32 bit value from addr.
  450.  
  451. 2!              ( d1 a1 --- )
  452.         Store a 32 bit value at addr.
  453.  
  454. 2DROP           ( n1 n2 --- )
  455.         Drop the top two elements of the data stack.
  456.  
  457. 3DROP           ( n1 n2 n3 --- )
  458.         Drop the top three elements of the data stack.
  459.  
  460. 2DUP            ( n1 n2 --- n1 n2 n1 n2 )
  461.         Duplicate the top two elements of the data stack.
  462.  
  463. 3DUP            ( n1 n2 n3 --- n1 n2 n3 n1 n2 n3 )
  464.         Duplicate the top three elements of the data stack.
  465.  
  466. 2SWAP           ( n1 n2 n3 n4 --- n3 n4 1n 2n )
  467.         Swap the top two pairs of numbers on the stack.  You can use
  468.         this operator to swap two 32 bit integers and preserve
  469.         their meaning as double numbers.
  470.  
  471. 2OVER           ( n1 n2 n3 n4 --- n1 n2 n3 n4 1n 2n )
  472.         Copy the second pair of numbers over the top pair.  Behaves
  473.         like 2SWAP for 32 bit integers.
  474.  
  475. 4DUP            ( n1 n2 n3 n4 --- n1 n2 n3 n4 n1 n2 n3 n4 )
  476.         Duplicate the top four elements of the stack.
  477.  
  478. 2ROT            ( n1 n2 n3 n4 n5 n6 --- n3 n4 n5 n6 n1 n2 )
  479.         rotates top three double numbers.
  480.  
  481. D+              ( d1 d2 --- d3 )
  482.         Add the two double precision numbers on the stack and
  483.         return the result as a double precision number.
  484.  
  485. DNEGATE         ( d1 d2 --- d3 )
  486.         Same as NEGATE except for double precision numbers.
  487.  
  488. S>D             ( n1 --- d1 )
  489.         Take a single precision number and make it double precision
  490.         by extending the sign bit to the upper half.
  491.  
  492. DABS            ( d1 --- d2 )
  493.         Return the absolute value of the 32 bit integer on the stack
  494.  
  495. D2*             ( d1 --- d2 )
  496.         32 bit left shift.
  497.  
  498. D2/             ( d1 --- d2 )
  499.         32 bit arithmetic right shift. Equivalent to divide by 2.
  500.  
  501. D-              ( d1 d2 --- d3 )
  502.         Subtract the two double precision numbers.
  503.  
  504. ?DNEGATE        ( d1 d2 --- d3 )
  505.         Negate the double number if the top is negative.
  506.  
  507. D0=             ( d1 --- f1 )
  508.         Compare the top double number to zero.  True if d = 0
  509.  
  510. D=              ( d1 d2 --- f1 )
  511.         Compare the top two double numbers.  True if d1 = d2
  512.  
  513. DU<             ( d1 d2 --- f1 )
  514.         Performs unsigned comparison of two double numbers.
  515.  
  516. D<              ( d1 d2 --- f1 )
  517.         Compare the top two double numbers.  True if d1 < d2
  518.  
  519. D>              ( d1 d2 --- f1 )
  520.         Compare the top two double numbers.  True if d1 > d2
  521.  
  522. DMIN            ( d1 d2 --- d3 )
  523.         Return the lesser of the top two double numbers.
  524.  
  525. DMAX            ( d1 d2 --- d3 )
  526.         Return the greater of the the top two double numbers.
  527.  
  528. *D              ( n1 n2 --- d1 )
  529.         multiplys two singles and leaves a double.
  530.  
  531. M/MOD  divides a double by a single, leaving a single quotient
  532.         and a single remainder. Division is floored.
  533.  
  534. MU/MOD  divides a double by a single, leaving a double quotient
  535.         and a single remainder. Division is floored.
  536.  
  537.  
  538. */      is a particularly useful operator, as it allows you to
  539.         do accurate arithmetic on fractional quantities.  Think of
  540.         it as multiplying n1 by the fraction n2/n3.  The intermediate
  541.         result is kept to full accuracy.  Notice that this is not the
  542.         same as * followed by /.  See Starting Forth for more examples.
  543.  
  544.